package com.zhang.controller;

import com.zhang.entity.ScriptTemplate;
import com.zhang.entity.response.ResponseResult;
import com.zhang.entity.vo.ActionBody;
import com.zhang.entity.vo.DeleteActionBody;
import com.zhang.entity.vo.ExecuteCommandBody;
import com.zhang.service.BroadcastService;
import com.zhang.service.IoTNettyServer;
import com.zhang.util.DeviceRedisUtil;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * User: 张
 * Date: 2024-11-15
 * Time: 19:14
 * Description:
 */
@RestController
@RequestMapping("/script")
public class BroadcastController {

    @Autowired
    private BroadcastService broadcastService;

    @PostMapping("/executeCommand")
    public ResponseResult<Object> executeCommand(@RequestBody ExecuteCommandBody executeCommandBody) {
        broadcastService.executeCommand(executeCommandBody);
        return ResponseResult.success();
    }

    @PostMapping("/addScriptTemplate")
    public ResponseResult<Object> addScriptTemplate(@RequestBody ScriptTemplate scriptTemplate) {
        return broadcastService.addScriptTemplate(scriptTemplate) ? ResponseResult.success() : ResponseResult.error();
    }

    @PostMapping("/getScriptTemplate")
    public ResponseResult<Object> getScriptTemplate(@RequestBody ScriptTemplate scriptTemplate,
                                                    @Param("pageNum") Integer pageNum,
                                                    @Param("pageSize") Integer pageSize) {
        return ResponseResult.success(broadcastService.getScriptTemplate(scriptTemplate, pageNum, pageSize));
    }

    @PostMapping("/updateScriptTemplate")
    public ResponseResult<Object> updateScriptTemplate(@RequestBody ScriptTemplate scriptTemplate){
        return broadcastService.updateScriptTemplate(scriptTemplate) ? ResponseResult.success() : ResponseResult.error();
    }

    @DeleteMapping("/deleteScriptTemplate")
    public ResponseResult<Object> deleteScriptTemplate(@RequestBody ScriptTemplate scriptTemplate){
        return broadcastService.deleteScriptTemplate(scriptTemplate) ? ResponseResult.success() : ResponseResult.error();
    }

    @PutMapping("/addAction")
    public ResponseResult<Object> addAction(@RequestBody ActionBody actionBody) {
        return broadcastService.addAction(actionBody) ? ResponseResult.success() : ResponseResult.error();
    }

    @DeleteMapping("/deleteAction")
    public ResponseResult<Object> deleteAction(@RequestBody DeleteActionBody deleteActionBody) {
        return broadcastService.deleteAction(deleteActionBody) ? ResponseResult.success() : ResponseResult.error();
    }
}
